//
//  SongsTableViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/16.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "SongsTableViewCell.h"
#import <UIImageView+WebCache.h>


#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@implementation SongsTableViewCell

- (void)dealloc
{
    [_songsModel release];
    [_numLabel release];
    [_image release];
    [_nameLabel release];
    [_singerName release];
    [_likeImageView release];
    [_playImageView release];
    [_floorLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.floorLabel = [UILabel new];
    self.floorLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.floorLabel];
    [_floorLabel release];
    
    self.image = [UIImageView new];
    [self.contentView addSubview:self.image];
    [_image release];
    
    
    self.nameLabel = [UILabel new];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.nameLabel];
    [_nameLabel release];
    
    
    self.singerName = [UILabel new];
    self.singerName.textColor = [UIColor grayColor];
    self.singerName.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.singerName];
    [_singerName release];
    
    self.likeImageView = [UIImageView new];
    [self.contentView addSubview:self.likeImageView];
    [_likeImageView release];
    
    self.numLabel = [UILabel new];
    self.numLabel.textColor = [UIColor grayColor];
    self.numLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.numLabel];
    [_numLabel release];
    
    self.playImageView = [UIImageView new];
    [self.contentView addSubview:self.playImageView];
    [_playImageView release];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.floorLabel.frame = CGRectMake(WIDTH_PRO(10), HEIGHT_PRO(20), WIDTH_PRO(20), HEIGHT_PRO(20));
    self.image.frame = CGRectMake(self.floorLabel.frame.size.width + WIDTH_PRO(20), HEIGHT_PRO(10), WIDTH_PRO(50), HEIGHT_PRO(50));
    self.nameLabel.frame = CGRectMake(self.image.frame.origin.x + WIDTH_PRO(60), HEIGHT_PRO(10), WIDTH_PRO(250), HEIGHT_PRO(20));
    self.singerName.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.size.height + HEIGHT_PRO(20), WIDTH_PRO(100), HEIGHT_PRO(20));
    self.likeImageView.frame = CGRectMake(self.singerName.frame.origin.x + self.singerName.frame.size.width + WIDTH_PRO(10), self.singerName.frame.origin.y , WIDTH_PRO(20), HEIGHT_PRO(20));
    self.numLabel.frame = CGRectMake(self.likeImageView.frame.origin.x + WIDTH_PRO(30), self.likeImageView.frame.origin.y, WIDTH_PRO(80), 20);
    self.playImageView.frame = CGRectMake(self.numLabel.frame.origin.x + self.numLabel.frame.size.width + WIDTH_PRO(10), HEIGHT_PRO(20), WIDTH_PRO(30), HEIGHT_PRO(30));
    
    
}

-(void)setSongsModel:(SongsModel *)songsModel
{
    if (_songsModel != songsModel) {
        [_songsModel release];
        _songsModel = [songsModel retain];
    }
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:songsModel.picUrl]];
    self.nameLabel.text = songsModel.name;
    self.singerName.text = songsModel.singerName;
    self.numLabel.text = [NSString stringWithFormat:@"%@", songsModel.favorites];
    self.likeImageView.image = [UIImage imageNamed:@"list_menu_unfavorite"];
    self.playImageView.image = [UIImage imageNamed:@"find_hotuser_play@2x"];
    
}

+(SongsTableViewCell *)songsTableViewCellWith:(UITableView *)tableView
{
    static NSString *cellIdentifier = @"cellIdentifier";
    SongsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[SongsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
